<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="Content-Type" content="text/html"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
    <title>获取设备摄像头 getUserMedia</title>
    <style>
        video {
            display: block;
            margin: 0 auto;
            width: 240px;
            height: 240px;
            background: #000;
            border-radius: 5px;
        }
    </style>
</head>
<body>
<div id="video"></div>
<div>
    <button id="open">打开</button>
</div>
<div id="result"></div>
</body>
<script src="qrscan.js"></script>
<script src="jsqr.js"></script>
<script>
    var ds = null;
    var scan = new QRScan('video');

    document.getElementById('open').onclick = function () {
        scan.openScan();
        ds = window.setInterval(function () {
            startScan();
        }, 1500);
    };

    var re_div = document.getElementById('result');

    function startScan() {
        scan.getImgDecode(function (res) {
            if (res && res.data) {
                var p = document.createElement('p');
                p.innerHTML = decodeURIComponent(res.data);
                re_div.appendChild(p);
                scan.closeScan();
                window.clearInterval(ds);
            }
        });
    };
</script>
</html>
